// Copyright (C) CompatibL Technologies LLC. All rights reserved.
// This code contains valuable trade secrets and may be used, copied,
// stored, or distributed only in accordance with a written license
// agreement and with the inclusion of this copyright notice. 

#region File Info
// File       : Scale.cs
// Description: ChordCreatorControl.Scale component implementation.
// Package    : ChordCreatorControl
//
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChordCreator.Services.ConfigurationServices;

namespace ChordCreator.Model
{
    /// <summary>
    /// Class represents music scale.  
    /// </summary>
    class Scale
    {
        private readonly Note tonic_;
        private List<Note> scaleNotes_;

        
        public Scale(string tonic)
        {
            tonic_ = XmlConfiguration.Instance.Handlerer.ScaleDisplaying.Where(x => x.DisplayedTonic == tonic).Select(x => x.Tonic).Single();
        }
        public Scale(Note tonic)
        {
            tonic_ = tonic;
        }

        public Note Tonic
        {
            get { return tonic_; }
        }

        /// <summary>
        /// Generates notes chromatic scale from scale tonic
        /// </summary>
        public Note[] GenerateChromaticScale()
        {
            List<Note> chromaticScale = new List<Note>();
            Note note = tonic_;
            chromaticScale.Add(note);
            while ((int)note < 11)
            {
                note++;
                chromaticScale.Add(note);
            }
            note = 0;
            while (note != tonic_)
            {
                chromaticScale.Add(note);
                note++;
            }
            return chromaticScale.ToArray();
        }

        /// <summary>
        /// Set`s concrete scale
        /// </summary>
        public void SetConreteScale(List<Note> notes)
        {
            scaleNotes_ = notes;
        }

        /// <summary>
        /// Get`s scale notes
        /// </summary>
        public ScaleNote[] GetConcreteScale()
        {
            List<ScaleNote> concreteScaleNotes = new List<ScaleNote>();
            for (int i=0; i<scaleNotes_.Count; i++)
            {
                concreteScaleNotes.Add(new ScaleNote(i+1, scaleNotes_[i]));
            }
            return concreteScaleNotes.ToArray();
        }

       
    }
}